[#-- freemarker CategoryList demo --]
<script type="text/javascript" src="[@core_url value='/dwr/engine.js'/]"></script>
<script type="text/javascript" src="[@core_url value='/dwr/interface/recordHandler.js'/]"></script>
<script type="text/javascript">
function addCookie(objName, objValue, objHours) {
	var str = objName + "=" + escape(objValue);
	if (objHours > 0) {
		var date = new Date();
		var ms = objHours * 3600 * 1000;
		date.setTime(date.getTime() + ms);
		str += "; expires=" + date.toGMTString();
	}
	document.cookie = str;
}
function getCookie(name) {
	var arr = document.cookie
			.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
	if (arr != null)
		return unescape(arr[2]);
	return null;
}
function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie(name);
	if (cval != null)
		document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

var record = (function() {
	function _addRecordListener${id}(id) {
		recordHandler.count(id, ["READ", "UP", "DOWN", "FAVOUR", "REPLY"],	{
			callback : function(data) {
				var _domRead = $('.record_read' + id);
				var _domUp = $('.record_up' + id);
				var _domDown = $('.record_down' + id);
				var _domFavour = $('.record_favour' + id);
				var _domReply = $('.record_reply' + id);
				if (_domRead.length > 0) {
				    _domRead.html(data[0]);
				} else {
				  	$('.record_read').html(data[0]);
				}
				if (_domUp.length > 0) {
				    _domUp.html(data[1]);
				} else {
				  	$('.record_up').html(data[1]);
				}
				if (_domDown.length > 0) {
				    _domDown.html(data[2]);
				} else {
				  	$('.record_down').html(data[2]);
				}
				if (_domFavour.length > 0) {
				    _domFavour.html(data[3]);
				} else {
				  	$('.record_favour').html(data[3]);
				}
				if (_domReply.length > 0) {
				    _domReply.html(data[4]);
				} else {
				  	$('.record_reply').html(data[4]);
				}
				[#-- 
				var $read = $('.record_read').html(data[0]);
				// 顶
				var $up = $('.record_up').html(data[1]);
				// 踩
				var $down = $('.record_down').html(data[2]);
				// 赞成
				var $favour = $('.record_favour').html(data[3]);
				// 反馈
				var $replay = $('.record_replay').html(data[4]);--]
			}, exceptionHandler : function(message) {
				alert("调用出现异常：" + message);
			}
		});// 
	}
	return {
		config : {
			allow : function(id, opt) {
				var key = id + opt;
				var _flag = getCookie(key);
				if (_flag == null) {
					addCookie(key, 'true', 365 * 24)
				}
				if (_flag == 'true') {
					addCookie(key, 'false', 365 * 24)
				}
				return getCookie(key) == 'true';
			}
		},
		up : function(id) {
			if (id == null) {
	            id = '${id}';
	        }
			if ("false" == "${repeat}") {
	        	if (!record.config.allow(id, 'up')) {
					alert("不能重复执行该操作.");
					return;
				}
	        }
			recordHandler.record(id, "UP", {
				callback : function(data) {
					var _dom = $('.record_up' + id);
				    if (_dom.length > 0) {
				        _dom.html(data);
				    } else {
				    	$('.record_up').html(data);
				    }
				}, exceptionHandler : function(message) {
					alert(message);
				}
			})
		},
		down : function(id) {
			if (id == null) {
	            id = '${id}';
	        }
			if ("false" == "${repeat}") {
    			if (!record.config.allow(id, 'down')) {
				    alert("不能重复执行该操作.");
					return;
				}
	        }
			recordHandler.record(id, "DOWN", {
				callback : function(data) {
				    var _dom = $('.record_down' + id);
				    if (_dom.length > 0) {
				        _dom.html(data);
				    } else {
				    	$('.record_down').html(data);
				    }
					//$('.down_' + id).html(data);
				}, exceptionHandler : function(message) {
					alert(message);
				}
			})
		},
		favour : function(id) {
			if (id == null) {
	            id = '${id}';
	        }		
	        if ("false" == "${repeat}") {
				if (!record.config.allow(id, 'favour')) {
					alert("不能重复执行该操作.");
					return;
				}
	        }
			recordHandler.record(id, "FAVOUR", {
				callback : function(data) {
					var _dom = $('.record_favour' + id);
				    if (_dom.length > 0) {
				        _dom.html(data);
				    } else {
				    	$('.record_favour').html(data);
				    }
					//$('.favour_' + id).html(data);
				}, exceptionHandler : function(message) {
					alert(message);
				}
			})
		},
		init : function(id) {
			if (id == null) {
	            id = '${id}';
	        }
			_addRecordListener${id}(id);
		}
	}
}());
$(function() {
	// 初始化统计对象；
	record.init('${id}');
});
</script>